package com.tulele.vtool.service.impl;

import com.tulele.vtool.mapper.LookArticleInfoMapper;
import com.tulele.vtool.model.LookArticleInfo;
import com.tulele.vtool.model.combinedEntity.*;
import com.tulele.vtool.service.ILookArticleInfoService;
import com.tulele.vtool.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class LookArticleInfoServiceImpl implements ILookArticleInfoService {

    @Autowired
    private LookArticleInfoMapper lookArticleInfoMapper;

    @Override
    public int recordLookArticleInfo(LookArticleInfo lookArticleInfo) {
        lookArticleInfoMapper.addLookArticleInfo(lookArticleInfo);
        return lookArticleInfo.getId();
    }

    @Override
    public int modifyLookArticleInfo(LookArticleInfo lookArticleInfo) {
        lookArticleInfoMapper.updateLookArticleInfo(lookArticleInfo);
        return lookArticleInfo.getId();
    }

    @Override
    public LookArticleStatisEntity getTotalLookArticleStatisInfo(Integer userId) {
        return lookArticleInfoMapper.queryTotalLookArticleStatisInfo(userId);
    }

    @Override
    public LookArticleStatisEntity getTodayLookArticleStatisInfo(Integer userId) {
        return lookArticleInfoMapper.queryTodayLookArticleStatisInfo(userId);
    }

    @Override
    public CombinedLookArticleUserInfo getUserLookArticleStatisInfo(LookArticleInfo lookArticleInfo) {
        return lookArticleInfoMapper.queryUserLookArticleStatisInfo(lookArticleInfo);
    }

    @Override
    public LookArticleInfo getLookOtherArticleInfo(LookArticleInfo lookArticleInfo) {
        return lookArticleInfoMapper.queryLookOtherArticleInfo(lookArticleInfo);
    }

    @Override
    public LookArticleInfo getUserOneBrandId(String springProfilesActive,Integer userId) {
        return lookArticleInfoMapper.getUserOneBrandId(springProfilesActive,userId);
    }

    @Override
    public List<LookUserArticleStatisInfo> getLookUserArticleStatisInfo(Integer userId, Integer recordSize) {
        return lookArticleInfoMapper.queryLookUserArticleStatisInfo(userId, recordSize);
    }

    @Override
    public List<CombinedLookArticleUserInfo> getLookArticleUserInfo(Integer userId) {
        return lookArticleInfoMapper.queryLookArticleUserInfo(userId);
    }

    @Override
    public int removeVirtualVisitUsers(List<String> virtualUserIds, Integer userId) {
        return lookArticleInfoMapper.deleteVirtualVisitUsers(virtualUserIds, userId);
    }

    @Override
    public Integer returnLookArticleId(Integer id) {
        return lookArticleInfoMapper.returnLookArticleId(id);
    }

    @Override
    public int getVisitorCount(Integer userId) {
        return lookArticleInfoMapper.getVisitorCount(userId);
    }

    @Override
    public List<CombinedCustomerInfo> getCurrentWeekReadData(Integer userId) {
        Date currentDate = DateUtil.getCurDate();
        String firstDayOfWeek = DateUtil.getFirstDayOfWeek(currentDate);
        String lastDayOfWeek = DateUtil.getLastDayOfWeek(currentDate);
        return lookArticleInfoMapper.getCurrentWeekReadData(userId, firstDayOfWeek, lastDayOfWeek);
    }

    @Override
    public List<CombinedCustomerInfo> getCurrentMonthReadData(Integer userId) {
        Date currentDate = DateUtil.getCurDate();
        String firstDayOfMonth = DateUtil.getFirstDayOfMonth(currentDate);
        String lastDayOfMonth = DateUtil.getLastDayOfMoth(currentDate);
        return lookArticleInfoMapper.getCurrentMonthReadData(userId, firstDayOfMonth, lastDayOfMonth);
    }

    @Override
    public List<CombinedCustomerYearInfo> getCurrentSeasonReadData(Integer userId) {
        // 按天统计
//        String firstDayOfSeason = DateUtil.getFirstDayOfSeason();
//        String lastDayOfSeason = DateUtil.getLastDayOfSeason();
//        return lookArticleInfoMapper.getCurrentSeasonReadData(userId, firstDayOfSeason, lastDayOfSeason);

        // 按月统计
        Integer firstMonthOfSeason = Integer.valueOf(DateUtil.getFirstMonthOfSeason());
        Integer lastMonthOfSeason = Integer.valueOf(DateUtil.getLastMonthOfSeason());
        return lookArticleInfoMapper.getCurrentSeasonReadDataByMonth(userId, firstMonthOfSeason, lastMonthOfSeason);
    }

    @Override
    public List<CombinedCustomerYearInfo> getCurrentYearReadData(Integer userId) {
        return lookArticleInfoMapper.getCurrentYearReadData(userId);
    }

    @Override
    public List<CombinedCustomerInfo> getCurrentWeekIntentionData(Integer userId) {
        Date currentDate = DateUtil.getCurDate();
        String firstDayOfWeek = DateUtil.getFirstDayOfWeek(currentDate);
        String lastDayOfWeek = DateUtil.getLastDayOfWeek(currentDate);
        return lookArticleInfoMapper.getCurrentWeekIntentionData(userId, firstDayOfWeek, lastDayOfWeek);
    }

    @Override
    public List<CombinedCustomerInfo> getCurrentMonthIntentionData(Integer userId) {
        Date currentDate = DateUtil.getCurDate();
        String firstDayOfMonth = DateUtil.getFirstDayOfMonth(currentDate);
        String lastDayOfMonth = DateUtil.getLastDayOfMoth(currentDate);
        return lookArticleInfoMapper.getCurrentMonthIntentionData(userId, firstDayOfMonth, lastDayOfMonth);
    }

    @Override
    public List<CombinedCustomerYearInfo> getCurrentSeasonIntentionData(Integer userId) {
        // 按天统计
//        String firstDayOfSeason = DateUtil.getFirstDayOfSeason();
//        String lastDayOfSeason = DateUtil.getLastDayOfSeason();
//        return lookArticleInfoMapper.getCurrentSeasonIntentionData(userId, firstDayOfSeason, lastDayOfSeason);

        // 按月统计
        Integer firstMonthOfSeason = Integer.valueOf(DateUtil.getFirstMonthOfSeason());
        Integer lastMonthOfSeason = Integer.valueOf(DateUtil.getLastMonthOfSeason());
        return lookArticleInfoMapper.getCurrentSeasonIntentionDataByMonth(userId, firstMonthOfSeason, lastMonthOfSeason);
    }

    @Override
    public List<CombinedCustomerYearInfo> getCurrentYearIntentionData(Integer userId) {
        return lookArticleInfoMapper.getCurrentYearIntentionData(userId);
    }

    @Override
    public int getArticleReadCount(Integer articleId) {
        return lookArticleInfoMapper.getArticleReadCount(articleId);
    }

    @Override
    public int getArticleLookCount(Integer articleId) {
        return lookArticleInfoMapper.getArticleLookCount(articleId);
    }
}
